
public class Dog {
        public String name;
        public int age;

        public void setDog(String name,int age) {
            //可以区分形参和成员变量
            this.name = name;
            this.age  = age;
        }
        public void setDog2(String name,int age) {
            name = name;
            age  = age;
        }
        public void printDog() {
            System.out.println("名字："+this.name+" 年龄："+this.age);
        }
        public void eat() {
            System.out.println(this.name +"正在吃狗粮");
        }
        public void run() {
            System.out.println(this.name +"正在跑");
        }
//        public static void eT1() {
//            System.out.println(this.name);//this不能用在静态类型中
//        }

        public static void main(String[] args) {
            Dog dog = new Dog();
            System.out.println(dog.age);//没初始化的话int 就是 0
            System.out.println(dog.name);//没初始化的话String 就是 null
            dog.setDog("小黑",10);
    //        dog.name = "小黑";
    //        dog.age = 10;
            dog.printDog();
            dog.eat();
            dog.run();
            System.out.println("==========");
            Dog dog1 = new Dog();
            dog1.setDog2("大黑",12);
    //        dog1.name = "大黑";
    //        dog1.age = 12;
            dog1.printDog();
            dog1.eat();
            dog1.run();
        }
}
